/* 
	直接引入使用
	MACaddress()
 */

const getMacAddress = {
  MACaddress: function (): string {
    const Build = plus.android.importClass('android.os.Build')

    // console.log(Build.deviceId)
    return JSON.stringify(Build)
    // const sdkInt = Build.VERSION.SDK_INT

    // if (sdkInt < 23) {
    //   return this.WifiInfoMac()
    // } else if (sdkInt === 23) {
    //   return this.ReaderMac()
    // } else {
    //   return this.NetworkMac()
    // }
  },

  // WifiInfoMac: function (): string {
  //   const Context = plus.android.importClass('android.content.Context')
  //   const WifiManager = plus.android.importClass('android.net.wifi.WifiManager')
  //   const wifiManager = plus.android
  //     .runtimeMainActivity()
  //     .getSystemService(Context.WIFI_SERVICE) as WifiManager
  //   const WifiInfo = plus.android.importClass('android.net.wifi.WifiInfo')
  //   const wifiInfo = wifiManager.getConnectionInfo() as WifiInfo

  //   return wifiInfo.getMacAddress()
  // },

  // ReaderMac: function (): string {
  //   try {
  //     const BufferedReader = plus.android.importClass('java.io.BufferedReader')
  //     const FileReader = plus.android.importClass('java.io.FileReader')
  //     const file = new FileReader('/sys/class/net/wlan0/address')
  //     const reader = new BufferedReader(file)
  //     const address = reader.readLine()
  //     reader.close()
  //     return address
  //   } catch (error) {
  //     console.error('Failed to read MAC address from file:', error)
  //     return this.NetworkMac()
  //   }
  // },

  // NetworkMac: function (): string {
  //   const NetworkInterface = plus.android.importClass('java.net.NetworkInterface')
  //   const networkInterfaces = NetworkInterface.getNetworkInterfaces()

  //   for (const networkInterface of networkInterfaces) {
  //     if (networkInterface.getName() === 'eth1' || networkInterface.getName() === 'wlan0') {
  //       const mac = networkInterface.getHardwareAddress()
  //       if (mac !== null) {
  //         return Array.from(mac).map(this.format).join(':')
  //       }
  //     }
  //   }

  //   this.isWifi()
  //   return '02:00:00:00:00:00'
  // },

  // format: function (byte: number): string {
  //   const hex = byte >= 0 ? byte.toString(16) : (256 + byte).toString(16)
  //   return hex.padStart(2, '0').toUpperCase()
  // },

  // isWifi: function (): void {
  //   if (plus.networkinfo.getCurrentType() !== plus.networkinfo.CONNECTION_WIFI) {
  //     plus.nativeUI.confirm('需要打开WiFi才能获取到MAC地址,是否去打开WiFi?', (event) => {
  //       if (event.index === 0) {
  //         const Intent = plus.android.importClass('android.content.Intent')
  //         const intent = new Intent(
  //           plus.android.runtimeMainActivity(),
  //           plus.android.importClass('com.android.settings.wifi.WifiSettings'),
  //         )
  //         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  //         plus.android.runtimeMainActivity().startActivity(intent)
  //       }
  //     })
  //   }
  // },
}

export default getMacAddress
